efform_onload = function ()
{
};  

button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCG99","query");
}

button_update_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行修改！"); return;
		}
	}
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCG99","update",true);
}

button_insert_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return;
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCG99","insert",true);
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCG99","delete",true);
	}); 
}

button_report_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	EFConfirm('确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCG99","report",true);
	});
}

button_revert_onclick = function (){
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;
	EFConfirm('确认要撤回吗?', '确认框', function(r) {
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdVirtualDate = grid.getCellValueByColumnName(rows[i], "fdVirtualDate"); // 上报日期
	  
	    var time = new Date((now()).replace(/-/g, "/")) - new Date((fdVirtualDate).replace(/-/g, "/"));
	    var day = parseFloat(time) / (1000*60*60*24);//与当前日期相差天数
	    if(day >7)
	    	{
	    	EFAlert("只能撤回一天内的记录");
			return;
	    	}
	}
//	if (isSelected("ef_grid_result") == 0)return; 
//	EFConfirm('确认要撤回吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCG99","revert",true);
	});
}
//
//efgrid_afterAddNewRow = function(grid_id) {
//	var grid = efgrid.getGridObject(grid_id);
//	var rows = grid.getCheckedRows();
//	if (grid_id == "ef_grid_result") {
//		for (var i = 0; i < rows.length; i++) {
//			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
//			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟");
//		}
//	}
//};

efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {

		var now = new Date();
		var year = now.getFullYear(); //年
		var month = now.getMonth() + 1; //月
		var day = now.getDate(); //日 
		var clock = year + "-";
		if (month < 10)
			clock += "0";
		clock += month + "-";
		if (day < 10)
			clock += "0";
		clock += day + " ";

		for (var i = 0; i < rows.length; i++) {
//			grid.setCellValue(rows[i], 0, "草拟", TYPE_DATA); //状态			
//			grid.setCellValue(rows[i], 2, year, TYPE_DATA); //年
//			grid.setCellValue(rows[i], 3, month, TYPE_DATA);//月
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟");
			grid.getBlockData().setCell(rows[i], "fdYear", year);
			grid.getBlockData().setCell(rows[i], "fdMonth", month);
			grid.getBlockData().setCell(rows[i], "fdCreateDate", clock);
		}
	}
	for(var i = 0 ; i < rows.length;i++){
		grid.getBlockData().setCell(rows[i], "fdKeyId", "");
	}
}

now = function(){
	//当前日期
	var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    if(month > 12) {
    	year = year + 1;				//下一年
    	month = 1;						//第一个月
    }
    if(month < 10) {
    	month = "0" + month;
    }
    var day = now.getDate();            //日 
    var clock = year + "-" + month + "-";
    if(day < 10) clock += "0";
    clock += day + " "; 
    return clock;
}
